package com.smmisia.article.entity;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.baomidou.mybatisplus.annotation.*;
import com.smmisia.article.dto.article.ArticleAddRequest;
import com.smmisia.common.enums.DeletedEnum;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 攻略游记表
 *
 * @TableName article
 */
@TableName(value = "article")
@Data

public class Article implements Serializable {
    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
    /**
     * 主键
     */
    @TableId(type = IdType.AUTO)
    @ExcelProperty(value = "文章ID", index = 0)
    @ColumnWidth(value = 20)
    private Integer id;
    /**
     * 用户id
     */
    @ExcelProperty(value = "用户ID", index = 1)
    @ColumnWidth(value = 20)
    private Integer userId;
    /**
     * 标题
     */
    @ExcelProperty(value = "标题", index = 2)
    @ColumnWidth(value = 20)
    private String title;
    /**
     * 照片
     */
    @ExcelProperty(value = "照片", index = 3)
    @ColumnWidth(value = 60)
    private String images;
    /**
     * 文字描述
     */
    @ExcelProperty(value = "文字描述", index = 4)
    @ColumnWidth(value = 20)
    private String content;
    /**
     * 经纬度
     */
    @ExcelProperty(value = "经纬度", index = 5)
    @ColumnWidth(value = 20)
    private String location;
    /**
     * 点赞数量
     */
    @ExcelProperty(value = "点赞数量", index = 6)
    @ColumnWidth(value = 20)
    private Integer liked;
    /**
     * 标签
     */
    @ExcelProperty(value = "标签", index = 7)
    @ColumnWidth(value = 20)
    private String tag;
    /**
     * 收藏数量
     */
    @ExcelProperty(value = "收藏数量", index = 8)
    @ColumnWidth(value = 20)
    private Integer favorite;
    /**
     * 类型,0/1,游记/攻略
     */
    @ExcelProperty(value = "类型,0/1,游记/攻略", index = 9)
    @ColumnWidth(value = 20)
    private Integer type;
    /**
     * 逻辑删除
     */
    @ExcelProperty(value = "逻辑删除", index = 10)
    @ColumnWidth(value = 20)
    private Integer deleted;
    /**
     * 是否显示
     */
    @ExcelProperty(value = "是否显示", index = 11)
    @ColumnWidth(value = 20)
    private Integer status;
    /**
     * 创建时间
     */
    @ExcelProperty(value = "创建时间", index = 12)
    @TableField(fill = FieldFill.INSERT)
    @ColumnWidth(value = 20)
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    @ExcelProperty(value = "更新时间", index = 13)
    @TableField(fill = FieldFill.UPDATE)
    @ColumnWidth(value = 20)
    private LocalDateTime updateTime;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Article other = (Article) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
                && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
                && (this.getTitle() == null ? other.getTitle() == null : this.getTitle().equals(other.getTitle()))
                && (this.getImages() == null ? other.getImages() == null : this.getImages().equals(other.getImages()))
                && (this.getContent() == null ? other.getContent() == null : this.getContent().equals(other.getContent()))
                && (this.getLocation() == null ? other.getLocation() == null : this.getLocation().equals(other.getLocation()))
                && (this.getLiked() == null ? other.getLiked() == null : this.getLiked().equals(other.getLiked()))
                && (this.getTag() == null ? other.getTag() == null : this.getTag().equals(other.getTag()))
                && (this.getFavorite() == null ? other.getFavorite() == null : this.getFavorite().equals(other.getFavorite()))
                && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
                && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()))
                && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
                && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
                && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
        result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode());
        result = prime * result + ((getImages() == null) ? 0 : getImages().hashCode());
        result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode());
        result = prime * result + ((getLocation() == null) ? 0 : getLocation().hashCode());
        result = prime * result + ((getLiked() == null) ? 0 : getLiked().hashCode());
        result = prime * result + ((getTag() == null) ? 0 : getTag().hashCode());
        result = prime * result + ((getFavorite() == null) ? 0 : getFavorite().hashCode());
        result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
        result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        return result;
    }

    @Override
    public String toString() {
        String sb = getClass().getSimpleName() +
                " [" +
                "Hash = " + hashCode() +
                ", id=" + id +
                ", userId=" + userId +
                ", title=" + title +
                ", images=" + images +
                ", content=" + content +
                ", location=" + location +
                ", liked=" + liked +
                ", tag=" + tag +
                ", favorite=" + favorite +
                ", type=" + type +
                ", deleted=" + deleted +
                ", status=" + status +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", serialVersionUID=" + serialVersionUID +
                "]";
        return sb;
    }

    public static Article create(ArticleAddRequest articleAddRequest){
        Article article = new Article();
        article.setTitle(articleAddRequest.getTitle());
        article.setContent(articleAddRequest.getContent());
        article.setImages(articleAddRequest.getImages());
        article.setLocation(articleAddRequest.getLocation());
        article.setType(articleAddRequest.getType());
        article.setTag(articleAddRequest.getTag());
        article.setLiked(0);
        article.setFavorite(0);
        article.setDeleted(DeletedEnum.IS_UNDELETED.getCode());
        article.setCreateTime(LocalDateTime.now());
        article.setUpdateTime(LocalDateTime.now());
        return article;
    }
}